//
//  GaoJingDetailViewController.m
//  Runone
//
//  Created by runone01 on 16/11/28.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "GaoJingDetailViewController.h"
#import "RequestHelper.h"
#import "MJExtension.h"
#import "DetailModel.h"

@interface GaoJingDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIView *MapView;
@property (weak, nonatomic) IBOutlet UITableView *TableView;
@property(nonatomic,strong)DetailModel *dataSource;
@end

@implementation GaoJingDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self request];
    _TableView.delegate=self;
    _TableView.dataSource=self;
    [_TableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CellID"];
    // Do any additional setup after loading the view from its nib.
}

- (void)request {
    RequestHelper *requestHelper=[[RequestHelper alloc] init];
    RequestGinsengModel *GetAllLastestVehicleDynamicModel=[[RequestGinsengModel alloc] init];
    GetAllLastestVehicleDynamicModel.URL=GetAllLastestVehicleDynamicURL;
    GetAllLastestVehicleDynamicModel.DataValue=[self dataValue];
    GetAllLastestVehicleDynamicModel.UpdatedTime=[requestHelper getCurrentTime];
    GetAllLastestVehicleDynamicModel.SystemCode=@"GuangleHighway";
    GetAllLastestVehicleDynamicModel.MethodName=@"GetAlarmVehicleInfo";
    requestHelper.block=^(RequestOutginseng *requestOutginseng,id dataValueModel) {
        NSDictionary *dic=[requestOutginseng.DataValue mj_JSONObject];
        _dataSource=[DetailModel mj_objectWithKeyValues:dic];
        [self.TableView reloadData];
    };
    [requestHelper RequestGinsengModel:GetAllLastestVehicleDynamicModel andPushController:self];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"CellID" forIndexPath:indexPath];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellID"];
    }
    switch (indexPath.row) {
        case 0:
            if (_dataSource.vehicleNo) {
                cell.textLabel.text=[NSString stringWithFormat:@"车牌号码：%@",_dataSource.vehicleNo];
            }
            else
            {
                cell.textLabel.text=[NSString stringWithFormat:@"车牌号码：暂无数据"];
            }
            break;
        case 1:
            if (_dataSource.VehicleType) {
                cell.textLabel.text=[NSString stringWithFormat:@"车辆类型：%@",_dataSource.VehicleType];
            }
            else
            {
                cell.textLabel.text=[NSString stringWithFormat:@"车辆类型：暂无数据"];
            }
            break;
        case 2:
            if (_dataSource.ownerName) {
                cell.textLabel.text=[NSString stringWithFormat:@"所属公司：%@",_dataSource.principalName];
            }
            else
            {
                cell.textLabel.text=[NSString stringWithFormat:@"所属公司：暂无数据"];
            }
            break;
        case 3:
            if (_dataSource.principalName) {
                cell.textLabel.text=[NSString stringWithFormat:@"联  系   人：%@",_dataSource.principalName];
            }
            else
            {
                cell.textLabel.text=[NSString stringWithFormat:@"联  系  人：暂无数据"];
            }
            break;
        case 4:
            if (_dataSource.principalTelephone) {
                cell.textLabel.text=[NSString stringWithFormat:@"联系电话：%@",_dataSource.principalTelephone];
            }
            else
            {
                cell.textLabel.text=[NSString stringWithFormat:@"联系电话：暂无数据"];
            }
            break;
        case 5:
            if (_dataSource.licenseCode) {
                cell.textLabel.text=[NSString stringWithFormat:@"运输证号：%@",_dataSource.licenseCode];
            }
            else
            {
                cell.textLabel.text=[NSString stringWithFormat:@"运输证号：暂无数据"];
            }
            break;
        default:
            break;
    }
   
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

-(NSString *)dataValue
{
    NSMutableDictionary *dicKey=[[NSMutableDictionary alloc] init];
    [dicKey setObject:@"VehicleNo" forKey:@"key"];
    [dicKey setObject:_CarID forKey:@"Value"];
//    NSMutableDictionary *dicValue=[[NSMutableDictionary alloc] init];
//    [dicValue setValue:_CarID forKey:@"Value"];
    NSMutableArray *mutabl=[[NSMutableArray alloc] init];
    [mutabl addObject:dicKey];
   // [mutabl addObject:dicValue];
    NSString *str=[mutabl mj_JSONString];
    return str;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
